directives.directive('ngDrop', ["$rootScope", "tools","$timeout", function ($rootScope, tools,$timeout) {
    return {
        restrict: 'AE',
        link: function (scope, element, attr) {

//            console.log("drop");
            element[0].addEventListener("dragover",function(e){
                e.preventDefault();
            },false);
            element[0].addEventListener('drop',function(event){
//                console.log(element[0]);
                event.preventDefault();

                var data=event.dataTransfer.getData("data");
                var json=$.parseJSON(data);


//                console.log("x:"+x+"y:"+y);

                //table
                if(json.dataType=="Table"){

                    var x=event.pageX+$("#rightBox .tableLink").scrollLeft();
                    var y=event.pageY+$("#rightBox .tableLink").scrollTop();
                    $rootScope.cardKey = Math.floor(Math.random()*10000000);
                    if($(element).hasClass("tableLink")){
                        $rootScope.$broadcast("UI_Cards_EV",json,x,y,$rootScope.cardKey);
                        return
                    }else{
//                        console.log("不是drop在这个元素。tableLink");
                    }

                }
                //Filed
                else if(json.dataType=="Filed"){
                    if($(element).hasClass("field")){
                        var TotableIndex=$(element).parent().attr("tablecardin");
                        if(TotableIndex==json.tableIncardIndex){
                            console.log("drag is fiead");
                            return;
                        }


//                        alert("left:"+$(element).offset().left+" top"+$(element).offset().top);

//                        console.log($(element).offset().top);
                        json.top2=$(element).offset().top+$("#rightBox .tableLink").scrollTop()+5;

                        var fileIndex=$(element).attr("fileIndex");
                        $rootScope.$broadcast("Insert_tableCard_linkCol_EV",json,TotableIndex,fileIndex);
                        return
                    }else{
                        console.log("不是drop在这个元素。content");
                    }

                }
                //link
                else if(json.dataType=="link"){
                    if($(element).hasClass("linkAreaCard")){

                        $('.tableLink .linkAreaCard').css({
                            "border-radius": "none",
                            "box-shadow":"none"
                        });

                        var dropIndex=$(element).attr("dropIndex");
                        json.dropIndex = dropIndex;
                        $rootScope.key = Math.floor(Math.random()*100000000);
                        $rootScope.$broadcast("Drop_Done_EV",json,$rootScope.key);
                    }else{
                        console.log("drop not in mubiao");
                        $('.tableLink .linkAreaCard').css({
                            "border-radius": "none",
                            "box-shadow":"none"
                        });
                    }
                }


//                console.log("data: ");
//                console.log(json);

            });
        }
    }
}]);
